<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //在问号处填写内容让代码支持a.name="name1";b.name="name2";
        // function obj(name){

        // }
        // obj.="name2";
        // var a=obj("name1");
        // var b=new obj;

        //创建全局函数
        function obj(name) {
            if (name) {
                this.name = name;
            }
            return this; //返回this引用
        }
        obj.prototype.name = "name2"; //设置原型对象
        var a = obj("name1"); //直接调用函数，this等于window，a等于window。
        var b = new obj; //等价于var b = new obj();调用函数实例化对象，this指向obj。
    </script>
</body>

</html>